package com.zhj.structure.linear.utils;

/**
 * 一个节点
 * @PackageName:com.zhj.structure.utils
 * @ClassName:Node
 * @auter: 朱慧杰
 * @date:2020/8/8 0008 15:02
 **/
public class LoopNode {

    // 节点内容
    private int data;
    // 下一个节点
    private LoopNode next = this;

    public LoopNode(int data) {
        this.data = data;
    }

    public void insertAfter(LoopNode node) {
        // 取出下一个节点
        LoopNode nextNext = this.next;
        this.next = node;
        this.next.next = nextNext;

    }

    public void removeNext() {
        LoopNode newNext = this.next.next;
        if(this.next.next == null) {
            this.next = null;
        }
        this.next = newNext;
    }

    // 获取下一个节点
    public LoopNode next() {
        return this.next;
    }

    // 获取数据
    public int getData() {
        return this.data;
    }

}
